package com.ai.bitcoin.jpa.dao;

import com.ai.bitcoin.constant.Bcc;
import com.ai.bitcoin.jpa.entity.BccRank;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Jason
 * @date 2018/3/27
 **/
public interface BccRankDao extends JpaRepository<BccRank, String> {

    Page<BccRank> findAll(Pageable pageable);

    List<BccRank> findByBccIdAndRecordState(String bccId, String recordState);

    List<BccRank> findByRecordStateOrderByValueScoreDesc(String recordState);

    Page<BccRank> findByRecordState(String recordState, Pageable pageable);

    List<BccRank> findByBatchNo(String batch);

    @Modifying
    @Query(nativeQuery = true, value = "update bcc_rank set record_state='" + Bcc.RecordState.PUBLISH + "' where batch_no =?1")
    void updateNewBatch2Publish(String batch);


    @Modifying
    @Query(nativeQuery = true, value = "DELETE from bcc_rank where batch_no <> ?1 or record_state='" + Bcc.RecordState.PUBLISH + "'")
    void deleteOldBatch(String unPublishBatch);

    @Modifying
    @Query(nativeQuery = true, value = "DELETE from bcc_rank where  record_state='" + Bcc.RecordState.UN_PUBLISH + "'")
    void deleteNoPublish();

    List<BccRank> findByBatchNoAndRecordStateOrderByValueScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByPotentialScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByGasScoreAsc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByValueUpPercentDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByPotentialUpPercentDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordState(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderBySupplyScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByNeedScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByInnerScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByMoodScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderBySafeScoreDesc(String batch, String recordState);

    List<BccRank> findByBatchNoAndRecordStateOrderByFutureScoreDesc(String batch, String recordState);

}
